<?php
namespace ms\components;

use yii\web\Controller;
use common\models\SysActionLog;

/**
 * 自定义控制器基类
 * @Description: 
 * @author: kai.gao
 * @date: 2014-11-21 上午10:27:35
 */
class Controller2015 extends Controller {
	public $enableCsrfValidation = false;
    public $action_id;
	/*
	 * @description:记录action执行完成时间
	 * @author:weilong.yin
	 */
    public function beforeAction($action){

      if (parent::beforeAction($action)) {
          // your custom code here

          $url = $action->controller->id.'/'.$action->id;
          $model = new SysActionLog();
          $model->request_url = $url;
          $model->request_user = f_s('user_name');
          $model->begin_time = (string)f_mtime();
          $model->end_time = '';
          $model->e_time = '';
          $model->flag = 0;
          $model->save();
          $this->action_id = $model->id;
          return true;  
      } else {
          return false;
      }
      
     }
     
    /* 
     * @description:记录action执行完成时间
     * @author:weilong.yin
     */
    public function afterAction($action, $result){
         $result = parent::afterAction($action, $result);
         // your custom code here
         $model = SysActionLog::findOne($this->action_id);
         if(!empty($model)){
             $e_time = f_mtime()-floatval($model->begin_time);
             $model->end_time = (string)f_mtime();
             $model->e_time = (string)$e_time;
             $model->flag = 1;
             $model->save();
         }
         return $result;
    }
}

?>